package main;

import java.awt.Color;

/**
 * this class will be the class that represents the player
 * @author 12817152
 *
 */

//STILL NEEDS AN INCREMENT TURN METHOD!!! TTM
public class Player {
	BasicMap bm;
	private UnitArray Units = new UnitArray(this);
	private City base; //need to write
	private resourceArray res;
	private Player Opponent;
	private PoliticalSystem pol;
	private FogOfWar fog;
	boolean resPane = false;
	boolean polSlider = false;
	Color c=new Color(200, 0, 0);
	String name="let's call the default name icarus";

	/**
	 * constructor form: city, colony array, map
	 * @param B - base city
	 * @param C - ColonyArray
	 * @param map - BasicMap
	 */
	public Player(City B, ColonyArray C, BasicMap map){
		base=B;
		res=new resourceArray(this);
		bm = map;
		B.placeInLand(bm);
		pol=new PoliticalSystem(this);
		fog=new FogOfWar(this);
		B.assignOwner(this);
	}
	
	/**
	 * constructor form: city, colony array, color, map
	 * @param B - base city
	 * @param C - colony array
	 * @param col - color (for units)
	 * @param map - BasicMap
	 */
	public Player(City B, ColonyArray C,  Color col, BasicMap map){
		base=B;
		res=new resourceArray(this);
		c=col;
		bm = map;
		pol=new PoliticalSystem(this);
		fog=new FogOfWar(this);
		B.placeInLand(bm);
		B.assignOwner(this);
	}
	
	/**
	 * returns political system
	 * @return political system
	 */
	public PoliticalSystem getPoliticalSystem(){
		return pol;
	}
	
	/**
	 * sets political system to p
	 * @param p - political system
	 */
	public void setPol(PoliticalSystem p){
		pol=p;
	}
	
	/**
	 * returns resourceArray
	 * @return resourceArray
	 */
	public resourceArray getRes(){
		return res;
	}
	
	/**
	 * sets opponent to op
	 * @param op - opposing player
	 */
	public void setOpponent(Player op){
		Opponent=op;
	}
	
	/**
	 * returns opponent
	 * @return opposing player
	 */
	public Player getOpponent(){
		return Opponent;
	}
	
	/**
	 * updates components as each turn passes
	 */
	public void incrementTurn() {
		//System.out.println("INCD");
		res.incrementTurn();
		Units.incrementTurn();
		pol.incrementTurn();
		//fog.incrementTurn();
		
	}
	
	/**
	 * returns unit array
	 * @return units unitArray
	 */
	public UnitArray getUnits(){
		return Units;
	}
	
	/**
	 * adds U to unitArray
	 * @param U - unit
	 */
	public void addUnit(Unit U){
		Units.addUnit(U);
	}
	
	/**
	 * returns false if any player posession is at specified (x, y)
	 * @param xpos - x coord
	 * @param ypos - y coord
	 * @return - false if player posession at specified coord, true if clear
	 */
	public boolean checkLocation (int xpos, int ypos){
		int[] location=base.getLocation();
		if(location[0]==xpos && location[1]==ypos){
			return false;
		}
		if(!Units.checkLocation(xpos, ypos))
			return false;
		if(!res.getColonies().checkLocation(xpos, ypos))
			return false;
		return true;
	}
	
	/**
	 * returns player name
	 * @return name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * sets player name to s
	 * @param s - string
	 */
	public void setName(String s) {
		name = s;
	}
	
	/**
	 * @return the color
	 */
	public Color getColor() {
		return c;
	}
	/**
	 * @param c the color to set
	 */
	public void setColor(Color c) {
		this.c = c;
	}
	
	/**
	 * upgrades specified unit/resource by specified amount
	 * @param name - name of resource
	 * @param stat - stat upgrade by
	 * @param type - type of object
	 * @param improve - improvement quantity
	 */
	public void upgrade(String name, String stat, String type, int improve){
		if(type.equals("Unit"))
			Units.upgrade(name, stat, improve);
		if(type.equals("Res"))
			res.upgrade(name, stat, improve);
	}
	
	/**
	 * upgrades econ tech
	 */
	public void upgradeEconTechLevel(){
		res.getTree().setEconTechLevel(res.getTree().getEconTechLevel()+1);
	}
	
	/**
	 * upgrades war tech
	 */
	public void upgradeWarTechLevel(){
		res.getTree().setWarTechLevel(res.getTree().getWarTechLevel()+1);
	}
	/**
	 * @return the basic map
	 */
	public BasicMap getBm() {
		return bm;
	}
	/**
	 * @param bm the basic map to set
	 */
	public void setBm(BasicMap bm) {
		this.bm = bm;
	}
	
	/**
	 * updates fog data and returns it
	 * @return fog data
	 */
	public boolean[][] getFogData() {
		//Units.incrementTurn();
		fog.incrementTurn();
		return fog.data;
	}
	
	/**
	 * returns city
	 * @return city
	 */
	public City getCity(){
		return base;
	}
}
